package com.nbicc.anon.ad.controller;

import com.nbicc.ad.po.AdInstance;
import com.nbicc.ad.service.IAdInstanceService;
import com.nbicc.ad.vo.AdInstanceQueryCondition;
import com.nbicc.common.RequestPageObj;
import com.nbicc.common.ResponseObj;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Api(value = "广告实例(匿名)" , description = "展示时使用")
@RestController
@RequestMapping(value = "/anon/ad/instance")
public class AnonAdInstanceController {

    @Resource(name = "AdInstanceService")
    private IAdInstanceService adInstanceService;

    @ApiOperation(value = "获取当前时刻下需要展示的广告")
    @PostMapping("/listInCurrent")
    public List<AdInstance> selectListByCatInCurrent(@RequestBody AdInstanceQueryCondition adInstanceQueryCondition){
        adInstanceQueryCondition.setShowTime(new Date());
        List<AdInstance> adInstanceList = adInstanceService.selectListByAdInstanceQueryCondition(adInstanceQueryCondition);
        return adInstanceList;
    }

    @ApiOperation(value = "按条件(分页等) 新闻", notes = "分页和条件查询")
    @PostMapping("/findApplyNewsInfo")
    @ResponseBody
    public ResponseObj findApplyNewsInfo(@RequestBody RequestPageObj<Map<String,Object>> requestPageObj){
        ResponseObj responseObj = adInstanceService.find(requestPageObj);
        adInstanceService.applyNewsInfoToAdInstanceList((List<AdInstance>) responseObj.getResult());
        return responseObj;
    }

}
